if(!window.NW3){
/**
* @version v 0.1.0 2009/10/19
* @package Nerv Widgets, nw.js
* @subpackage Nerv Progress Bar, calendar.js
* @author Manuele Castellan <manuele.castellan@gmail.com>
*
* @copyright    Copyright (C) Copyright (c) 2009 Manuele Castellan. All rights reserved.
* @license        GNU/GPLv3, see LICENSE
*
*  This program is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*/

 	var NW3 = function(){};
	NW3.version = '010';
	NW3.toString = function(){
		return "Nerv Progress Bar Plugin 0.1.1";
	};
	
	document.write(NW3);
}

/** plugins required */
//NW3.plugin.required(['window']);

NW3.progressbar = {
	ProgressBar : function(param) {
		oContainer = document.createElement('span');
		oDiv_outer = document.createElement('div');
		oDiv_inner = document.createElement('div');
		oDiv_progress = document.createElement('div');
		oDiv_message = document.createElement('div');
		
		oContainer.appendChild(oDiv_message);
		oContainer.appendChild(oDiv_outer);
		
		oDiv_outer.appendChild(oDiv_inner);
		oDiv_inner.appendChild(oDiv_progress);
		
		if(param.message) {
			param.message = true;
		}
		else {
			param.message = false;
		}
		
		obj = {
			object : oContainer,
			odiv_outer : oDiv_outer,
			odiv_inner : oDiv_inner,
			odiv_progress : oDiv_progress,
			odiv_message : oDiv_message,
			classprefix : 'NWProgressBar',
			width : param.width,
			message : param.message
		}
		
		// setta progressione
		obj.setProgression = function(val){
			if(NW3.core.string.isNumeric(val)){
				val = parseInt(val);
				if(val > 100) val = 100;
				else if(val <= 0) val = 0;
				
				obj.odiv_progress.style.width = val + '%';
			}
		}
		
		// setta messaggio
		obj.setMessage = function(text){
			if(text){
				obj.odiv_message.innerHTML = text;
			}
		}
		
		obj.setWidth = function(){
			obj.object.style.width = obj.width + 'px';
		}
		
		obj.setClass = function(){
			obj.object.className = obj.classprefix;
			obj.odiv_outer.className = obj.classprefix + 'Outer';
			obj.odiv_inner.className = obj.classprefix + 'Inner';
			obj.odiv_progress.className = obj.classprefix + 'Progress';
			obj.odiv_message.className = obj.classprefix + 'Message';
		}
		
		
		obj.output = function(){
			obj.setClass();
			obj.setWidth();
			
			obj.setProgression(0);
			
			/*if(param.message){
				obj.odiv_message.style.width = obj.width + 'px';
			}*/
			
			return obj.object;
		}
		
		obj.print = function(){
			NW3.core.object.print(obj.output());
		}
		
		obj.replace = function(targetElement){
			NW3.core.object.replace(targetElement, obj.output());
		};
		
		obj.insertAfter = function(targetElement){
			NW3.core.object.insertAfter(obj.output(), targetElement);
		};
		
		obj.insertBefore = function(targetElement){
			NW3.core.object.insertBefore(obj.output(), targetElement);
		};
		
		obj.appendChild = function(targetElement){
			NW3.core.object.appendChild(obj.output(), targetElement);
		};
		
		return obj;
	}
}